package com.hwpt.config;

import com.hwpt.interceptor.JwtTokenUserInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final JwtTokenUserInterceptor jwtTokenUserInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenUserInterceptor)
                // 拦截所有路径
                .addPathPatterns("/**")
                // 排除不需要JWT校验的路径
                .excludePathPatterns(
                        // 用户登录注册相关
                        "/user/auth/login/password",
                        "/user/auth/login/sms",
                        "/user/auth/register",
                        "/user/verifyCode/send",
                        "/user/verifyCode/verify",

                        //管理员相关
                        "/admin/auth/login",
                        "/admin/auth/logout",
                        
                        // Swagger/OpenAPI文档相关
                        "/v3/api-docs/**",
                        "/swagger-ui/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/doc.html",
                        
                        // 静态资源
                        "/static/**",
                        "/public/**",
                        "/resources/**",
                        
                        // 错误页面
                        "/error",
                        
                        // 健康检查端点（如果你有的话）
                        "/actuator/health"
                );
    }
}